<template>
  <div class="col card p10">
    <label class="title">取货控制</label>
    <div class="row_center mt">
      <label>列:</label>
      <el-input size="small" style="width: 60px;" v-model="ctx.col"/>
      <label class="ml">行:</label>
      <el-input size="small" style="width: 60px;" v-model="ctx.row"/>
    </div>
    <div class="row_center mt">
      <el-button @click="onClickPick" type="primary">测试取货</el-button>
      <el-button @click="onClickReset" type="warning">机器复位</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive } from 'vue';
import { dialog } from '../../service/ui';
import { pick_ctrl, reset_all } from '../../service/main_cmd';


interface Ctx {
  col: string,
  row: string,
}

const ctx = reactive<Ctx>({
  col: '1',
  row: '1',
});

async function onClickPick() {
  try {
    const col = parseInt(ctx.col);
    const row = parseInt(ctx.row);
    await pick_ctrl(col, row);
    dialog.succ('测试完成');
  } catch (msg) {
    dialog.err(msg);
  }
}

async function onClickReset() {
  try {
    await reset_all();
    dialog.succ('复位成功');
  } catch (msg) {
    dialog.err(msg);
  }
}

</script>
